package com.qkjia.day02;
//双重检查 线程安全
public class Test01_Singleton03 {
    private Test01_Singleton03(){
    }
    private static volatile Test01_Singleton03 instance=null;

    public static Test01_Singleton03 getInstance(){
        if(instance==null){
            synchronized (Test01_Singleton03.class){
                if(instance==null){
                    //memory =allocate();    //1：分配对象的内存空间
                    //ctorInstance(memory);  //2：初始化对象
                    //instanceA =memory;     //3：设置instance指向刚分配的内存地址
                    instance=new Test01_Singleton03();
                    //JVM的重排序
                    //memory =allocate();    //1：分配对象的内存空间
                    //instanceA =memory;     //3：设置instance指向刚分配的内存地址
                    //ctorInstance(memory);  //2：初始化对象
                }
            }
        }
        return instance;
    }


}
